﻿using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Xml.Linq;
using FlickrXplorer.Web.Objects;

namespace FlickrXplorer.Web.Plugin
{
  internal class LoadMainPhotoEventProxy : BuilderEventProxy
  {
    internal Func<PhotoDetail, String> TitleMethod { get; set; }
    internal Func<PhotoDetail, String> BodyMethod { get; set; }

    public LoadMainPhotoEventProxy(FlickrXplorerPlugin plugin) 
      : base(plugin)
    {
      plugin.LoadMainPhoto += new EventHandler<LoadMainPhotoEventArgs>(plugin_LoadMainPhoto);
    }

    private void plugin_LoadMainPhoto(object sender, LoadMainPhotoEventArgs e)
    {
      string template = 
        @"
          <h3>{0}</h3>
          <p>{1}</p>
         ";

      string title;
      string body;

      // Execute the delegate functions to grab each piece of content
      title = this.TitleMethod != null ? this.TitleMethod(e.PhotoDetail) : null;
      body = this.BodyMethod != null ? this.BodyMethod(e.PhotoDetail) : null;

      e.Content = String.Format(
        template,
        title ?? "(none)",
        body ?? "(none)");
    }
  }
}
